import 'dart:math';

import 'package:flutter/material.dart';

class TransformAnimationDemo extends StatefulWidget {
  @override
  _TransformAnimationDemoState createState() => _TransformAnimationDemoState();
}

class _TransformAnimationDemoState extends State<TransformAnimationDemo> with SingleTickerProviderStateMixin{
  Animation<double> _animation;
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(duration: Duration(milliseconds: 1000),vsync: this);
    _animation = Tween<double>(begin: 0,end: pi).animate(_controller);
    _controller.addListener((){
      setState(() {

      });
    });

    _animation.addStatusListener((status){
      if (status == AnimationStatus.completed) {
        _controller.reverse();
      }
      else {
        _controller.forward();
      }
    });
  }

  @override
  void dispose ()
  {
    _controller.dispose();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('转场动画'),
      ),
      body: Builder(builder:(context){
        return Container(
          child: Column(
            children: <Widget>[
              FlutterLogo(size: 100.0,),
              RaisedButton(
                child: Text('动画开始'),
                onPressed: (){
                  _controller.forward();
                },
              )
            ],
          ),
          transform: Matrix4.rotationZ(_animation.value),
        );
      }),
    );
  }
}
